/**
 * 
 */
package com.alphasystem.commerce.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.PropertyResourceBundle;

/**
 * @author Syed Farhan Ali
 */
public class MessageResourceBundle extends PropertyResourceBundle {

	public static MessageResourceBundle getInstance(String bundleName) {
		MessageResourceBundle bundle = null;
		try {
			InputStream is = AppUtil.getResourceAsStream(bundleName);
			if (is == null) {
				throw new RuntimeException(bundleName + " not found");
			}
			bundle = new MessageResourceBundle(is);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return bundle;
	}

	/**
	 * @param stream
	 * @throws IOException
	 */
	public MessageResourceBundle(InputStream stream) throws IOException {
		super(stream);
	}

	/**
	 * @param key
	 * @return
	 */
	public String getFormattedString(String key, Object... arguments) {
		return MessageFormat.format(getString(key), arguments);
	}

}
